package com.hnust.service.impl;

import com.hnust.api.ReleaseExamApi;
import com.hnust.api.TestPaperApi;
import com.hnust.api.TestPaperApis;
import com.hnust.domain.*;
import com.hnust.service.TestPaperService;
import com.hnust.store.PaperListDataStore;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Callback;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人：zhangRuWang
 * 创建时间：2020/10/28
 * 描述：
 */
@Service("testPaperService")
public class TestPaperServiceImpl implements TestPaperService {
    @Autowired
    private TestPaperApi testPaperApi;

    @Autowired
    private TestPaperApis testPaperApis;

    @Autowired
    private PaperListDataStore paperListDataStore;

    @Autowired
    private ReleaseExamApi releaseExamApi;


    @Override
    public void getCourseData(Callback<Result<List<CourseData>>> callback, String id, String token) {
        testPaperApi.getCourseData(id, token).enqueue(callback);
    }

    @Override
    public void getCourseQuesList(Callback<Result<List<QuestionType>>> callback, String token, String id) {
        testPaperApi.getCourseQuesList(token, id).enqueue(callback);
    }

    @Override
    public void getQuestion(Callback<Result<SubjectInfo>> callback, String token,String course_id, String type_id, String now_page) {
        testPaperApi.getQuestion(token,course_id,type_id,now_page).enqueue(callback);
    }

    @Override
    public void getQuesByCon(Callback<Result<SubjectInfo>> callback, String token, String id, String course_id, String type_id, String keyword,Integer diff, String now_page) {
        testPaperApi.getQuesByCon(token, id,course_id,type_id,keyword,diff,now_page).enqueue(callback);
    }

    @Override
    public void checkPaperRepeat(Callback<Result<List<RepeatQues>>> callback, String token, String id, String course_id, List<String> subject_ids) {
        testPaperApi.checkPaperRepeat(token,id,course_id,subject_ids).enqueue(callback);
    }

    @Override
    public void createPaper(Callback<Result<String>> callback, GeneratePaperInfoRecord generatePaperInfoRecord) {
        testPaperApi.create(generatePaperInfoRecord).enqueue(callback);
    }

//    @Override
//    public void createPaper(Callback<Result<String>> callback, String teacherId, String collegeId, String courseNumber, String examTime,String passRate, String grade, String type, List<PaperQuestionRecord> questions) {
//        testPaperApi.create(teacherId,collegeId,courseNumber,examTime,passRate,grade,type,questions).enqueue(callback);
//    }

    @Override
    public void getPaperpic(Callback<ResponseBody> callback, String paperId) {
        testPaperApi.getPaperpic(paperId).enqueue(callback);
    }

    @Override
    public void getPaperList(Callback<Result<PaperInfo>> callback, String token, String id, String course_id, int now_page) {
//        testPaperApi.getPaperList(token,id,course_id,now_page).enqueue(callback);
    }

//    @Override
//    public void delTestPaper(Callback<Result<Integer>> callback, String token, List<String> paper_ids) {
//        testPaperApi.delTestPaper(token,paper_ids).enqueue(callback);
//    }

//    @Override
//    public void changePaperType(Callback<Result<Integer>> callback, String token, List<String> paper_ids) {
//        testPaperApi.changePaperType(token,paper_ids).enqueue(callback);
//    }


//    @Override
//    public void getPaperPreview(Callback<Result<Object>> callback, String paperId) {
//        testPaperApi.getPaperPreview(paperId).enqueue(callback);
//    }

//    @Override
//    public void removePaperType(Callback<Result<Integer>> callback, String token, List<String> paper_ids) {
//        testPaperApi.removePaperType(token,paper_ids).enqueue(callback);
//    }


    @Override
    public void getPaperdocx(Callback<ResponseBody> callback, String paperId) {
        testPaperApi.getPaperdocx(paperId).enqueue(callback);
    }

    @Override
    public void getPaperAnswerdocx(Callback<ResponseBody> callback, String paperId) {
        testPaperApi.getPaperAnswerdocx(paperId).enqueue(callback);
    }

    @Override
    public void getPaperPlandocx(Callback<ResponseBody> callback, String paperId) {
        testPaperApi.getPaperPlandocx(paperId).enqueue(callback);
    }

    @Override
    public void getAutoPaper(Callback<Result<List<SubjectData>>> callback, String course_id, RequestBody list, String token) {
        testPaperApi.getAutoPaper(course_id,list,token).enqueue(callback);
    }

    @Override
    public void setDiasbleQue(Callback<Result<Boolean>> callback, String token, List<String> subject_ids) {
        testPaperApi.setDiasbleQue(token,subject_ids).enqueue(callback);
    }
    //有callback的发布考试
//    @Override
//    public void releasePaper(Callback<Result<String>> callback,PublishPaperInfo publishPaperInfo){
//        //将考试信息作为参数传入后端发布考试
//        releaseExamApi.publishPaper(publishPaperInfo);
//    }

    //教师端补充
    @Override
    public Result<List<Test>> getExamList(String subject, String pap_name){
        return testPaperApi.getExamList(subject, pap_name);
    }

    @Override
    public Result<List<Test>> getAllExams(){
        return testPaperApi.getAllExams();
    }

    // 获取待批阅所有试卷列表
    @Override
    public Result<List<Test>> getNeedCorrectExams(String teaNum) {
        return testPaperApi.getNeedCorrectExams(teaNum);
    }

    @Override
    public Result<List<Test>> getUnstartedExams(String teaNum) {
        return testPaperApi.getUnstartedExams(teaNum);
    }
    //教师端修改
    @Override
    public Result<Object> changePaperType(ArrayList<String> paper_ids){
        return testPaperApi.changePaperType(paper_ids);

    }
    @Override
    public Result<Object> removePaperType(ArrayList<String> paper_ids){
        return testPaperApi.removePaperType(paper_ids);
    }
    @Override
    public Result<Object> deletePaper(ArrayList<String> paper_ids){
        return testPaperApi.deletePaper(paper_ids);
    }

    //试卷修改
    //获取考试信息
    @Override
    public Result<TestMessage> getTest(String paperId){
        System.out.println(" getTest内，paperId:"+paperId);
        System.out.println("testPaperApi的返回："+testPaperApi.getTest(paperId).toString());
        return testPaperApi.getTest(paperId);
    }
    //获取考试试题
    //获取选择题
    @Override
    public Result<List<ChoiceTestQuestions>> getChoiceQuestions(String paperId){
        return testPaperApi.getChoiceQuestions(paperId);
    }
    //获取判断题
    @Override
    public Result<List<JudgeTestQuestions>> getJudgeQuestions(String paperId){
        return testPaperApi.getJudgeQuestions(paperId);
    }
    //获取填空题
    @Override
    public Result<List<GapTestQuestions>> getGapQuestions(String paperId){
        return testPaperApi.getGapQuestions(paperId);
    }
    //获取简答题
    @Override
    public Result<List<EssayTestQuestions>> getEssayQuestions(String paperId){
        return testPaperApi.getEssayQuestions(paperId);
    }


    //无callback的发布考试
    @Override
    public Result<String> releasePaper(PublishPaperInfo publishPaperInfo){
        return releaseExamApi.publishPaper(publishPaperInfo);
    }

}
